package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.UnitApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.*;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.dao.UnitDao;
import com.clickpaas.materialsprocurement.entity.UnitEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Repository
public class UnitDaoImpl implements UnitDao {

    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private UnitApi unitApi;

    private List<UnitDTOResponse> queryUnitInfo(UnitDTO unitDTO){
        DataResponseListUnitDTO unitUsingPOST = unitApi.findUnitUsingPOST(unitDTO);
        if(null == unitUsingPOST
                || null == unitUsingPOST.getData()
                || unitUsingPOST.getData().size()<=0
                || !"SUCCESS".equals(unitUsingPOST.getMessage())){
            log.info("当前查询的数据：【{}】",unitUsingPOST);
            return null;
        }
        return unitUsingPOST.getData();
    }

    /**
     * 根据条件查询单位对象数据
     *
     * @param unitEntity
     */
    @Override
    public List<UnitDTOResponse> getUnitByCondtion(UnitEntity unitEntity) {
        UnitDTO unitDTO = materalsDtoBean.unitDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(unitEntity,unitDTO);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",unitEntity);
        }
        return queryUnitInfo(unitDTO);
    }
}
